//
//  SEGUrlAddress.m
//  Commom
//
//  Created by 山刘 on 2019/3/28.
//  Copyright © 2019年 山刘. All rights reserved.
//

#import "SEGUrlAddress.h"
#import "SEGBasicBussinessCommonDefine.h"

#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

#if __has_include(<SEGPlatform/SEGPlatformManager.h>)
#import <SEGPlatform/SEGPlatformManager.h>
#else
#import "SEGPlatformManager.h"
#endif

#if __has_include(<Commom/YYBaseHeader.h>)
#import <Commom/YYBaseHeader.h>
#else
#import "YYBaseHeader.h"
#endif


@implementation SEGUrlAddress

/**
 * 新调查
 * @author Sam
 */
+(NSString*)segNewSurvey:(NSString*)code{
    return [NSString stringWithFormat:@"%@/h5/questionnaire-survey/?#/survey/surveyDetail?isHideHeader=1&wjId=%@", kClientRootURL, code];
}
/**
 * 活动抽奖,签到有礼（好运有礼）
 * @author Helen
 */
+(NSString*)segWebActivity:(NSString *)userID {
    NSString* roodom = [[NSDate date] stringNoUTCDateByFormatString:@"yyyyMMdd"];
    NSString* roodom1 = [[NSDate date] stringNoUTCDateByFormatString:@"HHmmss"] ;
    return [NSString stringWithFormat:@"%@/lottery/lotteryForIOS.html?userId=%@&_rand=%@%@",
            kClientRootURL,
            ValueToString(userID),
            roodom,
            roodom1];
}

/**
 * 公用拼接请求：社区资讯,物业通知、推送详情
 * @author Helen
 */
+(NSString*)segWebCommunityInfo:(NSString*)objId{
    //    return [NSString stringWithFormat:@"%@%@#/notice/detail?objId=%@&source=%@&app_platform_code=%@&scheme=%@",
    //            kClientRootURL,
    //            kNewShareURLPre,
    //            objId,
    //            kSource,
    //            kAppPlatformCode,
    //            kOpenAppScheme];
    return [NSString stringWithFormat:@"%@/h5/community-news-h5/?#/news/newsDetail?infoId=%@&source=%@&app_platform_code=%@&scheme=%@&isHideHeader=1",
            kClientRootURL,
            objId,
            kSource,
            kAppPlatformCode,
            kOpenAppScheme];
}

/**
 * 招商一卡通 （组件里面没有招商 暂时注释）
 * @author Helen
 */
+(NSString *)segWebCMHK_YIKATOG{
//    //cid：用户id      uid: custId客户标识     cmid:小区id   timt:时间戳    sign：签名
//    //http://appsrv.cmpmc.com:1005/h5/app/AppUser/Auth/MyCard?K=    &uid=%@&cid=%@&cmid=%@&time=%ld&sign=xxx
//
//    //uid: custId客户标识
//    NSString *custIdStr = [SEGProfileManager sharedManager].profile.custId;
//    //时间戳
//    NSInteger intervalTime = (NSInteger)[[NSDate date] timeIntervalSince1970] * 1000;
//    NSString *timeStr = [NSString stringWithFormat:@"%zd",intervalTime];
//
//    //秘钥 -- 客户端秘钥，App接口专用
//    NSString *AppSecret = @"OLPWDDFAMAMRUAEXHIZEBVXGOPOQEZ";
//    //测试用数据 uid=87&cid=2394311
//    //NSString *data = [NSString stringWithFormat:@"K=1000200001&uid=87&cid=2394311&cmid=%@&time=%@",kAccountCommunityID,timeStr];
//    //正式数据
//    NSString *data = [NSString stringWithFormat:@"K=1000200001&uid=%@&cid=%@&cmid=%@&time=%@&phone=%@&name=%@&idno=%@",kAccountUserID,custIdStr,kAccountCommunityID,timeStr,kAccountMobile,@"",@""];
//
//    //签名
//    NSString *MD5STRING = [NSString stringWithFormat:@"%@|%@",data,AppSecret];
//    NSString *signStr = [SEGUtils md5:MD5STRING].uppercaseString;
//
//    NSString *loadUrl = [NSString stringWithFormat:@"http://appsrv.cmpmc.com:1005/h5/app/AppUser/Auth/MyCard?%@&sign=%@",data,signStr];
//    return loadUrl;
    return @"";
}

/**
 * 招商在线缴费
 * @author Helen
 * @param serviceUrl  字典中取服务地址
 */
+(NSString *)segWebCMHKPayOnline:(NSString *)serviceUrl custID:(NSString *)custID {
    return [NSString stringWithFormat:@"%@%@",[serviceUrl componentsSeparatedByString:@"#"].lastObject,[self seg_urlStringForcmhkWithCustID:custID]];
}

/**
 * 数字社区
 * @author Helen
 * @param accountType accountType
 * @param submitAuthFlag submitAuthFlag
 * @param communityID communityID
 */
+(NSString *)segWebDigitalCommunityWithAccountType:(NSString *)accountType submitAuthFlag:(NSString *)submitAuthFlag communityID:(NSString *)communityID {
//    SEGProfileModel *account = [SEGProfileManager sharedManager].profile;
//    return [NSString stringWithFormat:@"%@%@#/digitalCommunity?communityId=%@&badge=%@&user_type=%@",
//            kClientRootURL,
//            kNewShareURLPre,
//            kAccountCommunityID,
//            [ValueToString(account.type) isEqualToString:@"5"] ? ([ValueToString(account.submitAuthFlag) isEqualToString:@"1"] ? @"0" : @"1") : @"0",
//            ValueToString(account.type)];
    
    return [NSString stringWithFormat:@"%@%@#/digitalCommunity?communityId=%@&badge=%@&user_type=%@",
               kClientRootURL,
               kNewShareURLPre,
               ValueToString(communityID),
               [ValueToString(accountType) isEqualToString:@"5"] ? ([ValueToString(submitAuthFlag) isEqualToString:@"1"] ? @"0" : @"1") : @"0",
               ValueToString(accountType)];
}

/**
 * 访客管理
 * @author Helen
 * @param  organizationID organizationID
 * @param  tel  tel
 * @param  userName userName
 */
+(NSString*)segWebVisitorManagementWithOrganizationID:(NSString *)organizationID tel:(NSString *)tel userName:(NSString *)userName {
    // SEGProfileModel *account = [SEGProfileManager sharedManager].profile;
    NSString *secretId = @"EmnORxY9w5MziPyMxLDxq9G0WhxycPl97uCjdiyhiF5N21UX7p";
    NSString *secretKey = @"ksQOE2KW56ZH9wOECHdl";
    
    // NSString *orgId = ValueToString(account.jobCommunity);
    // NSString *mobile = ValueToString(account.tel);
    // NSString *userName = [account.nickname stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    // NSString *timeStamp = [NSString stringWithFormat:@"%zd",[[NSDate date] timeIntervalSince1970] * 1000];
    // NSString *srcStr = [NSString stringWithFormat:@"mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@",
    //                     mobile,orgId,secretId,timeStamp,ValueToString(account.nickname)];
    // NSString *signature = [SEGUtils seg_Hmacsha1:srcStr key:secretKey];
    // NSString *signature_URLEncod = [self URLEncodedString:signature];


    // return [NSString stringWithFormat:@"https://visitor.zhimahezi.net/julin/?mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@&signature=%@&end=0",
            // mobile,orgId,secretId,timeStamp,userName,signature_URLEncod];

    NSString *orgId = ValueToString(organizationID);
    NSString *mobile = ValueToString(tel);
    userName = [ValueToString(userName) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *timeStamp = [NSString stringWithFormat:@"%zd",[[NSDate date] timeIntervalSince1970] * 1000];
    NSString *srcStr = [NSString stringWithFormat:@"mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@",
                        mobile,orgId,secretId,timeStamp,ValueToString(userName)];
    NSString *signature = [SEGUtils seg_Hmacsha1:srcStr key:secretKey];
    NSString *signature_URLEncod = [self URLEncodedString:signature];
   
    return [NSString stringWithFormat:@"https://visitor.zhimahezi.net/julin/?mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@&signature=%@&end=0",
            mobile,orgId,secretId,timeStamp,userName,signature_URLEncod];
}

+ (NSString *)URLEncodedString:(NSString*)content
{
    if (!content) return @"";
    NSString *unencodedString = content;
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)unencodedString,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    return encodedString;
}

/**
 * 积分商城2.0商品详情页
 * @author Helen
 * @param href  拼接后缀
 */
+(NSString *)segWebIntegralMall:(NSString *)href{
    return [NSString stringWithFormat:@"%@%@%@",kClientRootURL, @"/h5/bonuses-h5-v2/index.html#/commodityDetail/",href];
}

/**
 * 招商在线缴费链接
 * @author Sam
 * @param custID  [SEGProfileManager sharedManager].profile.custId
 */
+(NSString*)seg_urlStringForcmhkWithCustID:(NSString *)custID {

    NSDate *now = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyyMMddHHmmss";
    NSString *timeString = [formatter stringFromDate:now];
    NSString *urlString = [NSString stringWithFormat:@"%@;%@;%@",timeString,ValueToString(custID),kWeChatAppId];

    NSData *data = [urlString dataUsingEncoding:NSUTF8StringEncoding];

    return [data base64EncodedStringWithOptions:0];
}

@end

